{include file='common/header'}
<link href="__ROOT__/static/plugin/jquery-treegrid/css/jquery.treegrid.css" rel="stylesheet" type="text/css"/>
<div class="page-bar">
    {include file='common/nav'}
    <div class="page-toolbar">
        <div class="btn-group pull-right">
            <button type="button" class="btn btn-fit-height grey-salt dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="1000" data-close-others="true"> 菜单
                <i class="fa fa-angle-down"></i>
            </button>
            <ul class="dropdown-menu pull-right" role="menu">
                <li>
                    <a href="{:url('system/admin_menu_add')}">
                        <i class="icon-plus"></i> 新增菜单</a>
                </li>
            </ul>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="portlet light form-fit ">
            <div class="portlet-body form">


                <table class="table tree">
                    <colgroup>
                        <col class="col-sm-4"/>
                        <col class="col-sm-3"/>
                        <col class="col-sm-1"/>
                        <col class="col-sm-1"/>
                        <col class="col-sm-2"/>
                    </colgroup>
                    <tr>
                        <th>菜单名称</th>
                        <th class="hidden-xs">链接地址</th>
                        <th class="hidden-xs text-center">显示</th>
                        <th class="hidden-xs">排序</th>
                        <th>操作</th>
                    </tr>
                    {foreach $list as $menu}
                    <tr class="treegrid-{$menu.id}{if $menu.p_id>0} treegrid-parent-{$menu.p_id}{/if} ks-form" id="tr{$menu.id}">
                        <td class="form-inline">
                            <i class="{$menu.icon}"></i>
                            <input class="form-control" type="text" name="name" value="{$menu.name}"/>
                            <span class="font-grey-cascade">(ID:{$menu.id})</span>
                            <a href="{:url('system/admin_menu_add',['p_id'=>$menu.id])}" class="icon-plus hidden-xs tooltips" data-container="body" data-placement="right" data-html="true" data-original-title="增加子菜单"></a>
                        </td>
                        <td class="hidden-xs"><input class="form-control" type="text" name="url" value="{$menu.url}"/></td>
                        <td class="hidden-xs text-center">
                            <div class="mt6">
                                <input type="checkbox" class="icheck-flat" name="status" {if $menu.status}checked{/if}/>
                            </div>
                        </td>
                        <td class="hidden-xs"><input class="form-control" type="text" name="sort" value="{$menu.sort}"/></td>
                        <td>
                            <a href="{:url('system/admin_menu_edit',['id'=>$menu.id])}" class="btn btn-xs blue">
                                <i class="fa fa-edit"></i> 编辑
                            </a>
                            <a href="javascript:;" class="btn btn-xs red btn_delete">
                                <i class="fa fa-times"></i> 删除
                            </a>
                            <input class="form-control" type="hidden" name="id" value="{$menu.id}"/>
                        </td>
                    </tr>
                    {/foreach}   
                </table>

            </div>
        </div>
    </div>
</div>



{include file='common/footer'}
<!--树形表格-------------------------------------------------------开始-->
<script src="__ROOT__/static/plugin/jquery-treegrid/js/jquery.treegrid.js" type="text/javascript"></script>
<script src="__ROOT__/static/plugin/jquery-treegrid/js/jquery.treegrid.bootstrap3.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('.tree').treegrid({
            expanderExpandedClass: 'fa fa-minus-square',
            expanderCollapsedClass: 'fa fa-plus-square'
        });
    });
</script>
<!--树形表格-------------------------------------------------------结束-->

<!--快速编辑菜单事件-------------------------------------------------------开始-->
<script>
    $(function () {
        $input = $('.ks-form').find("input[type='text']");
        $input.on('change', function () {
            $(this).ajaxPost({
                loading: false,
                url: "{:url('system/admin_menu_update_quick')}"
            })
        })

        $checkbox = $('.ks-form').find("input[type='checkbox']");
        $checkbox.on('ifChanged', function () {
            $(this).ajaxPost({
                loading: false,
                url: "{:url('system/admin_menu_update_quick')}"
            })
        });

    })
</script>
<!--快速编辑菜单事件-------------------------------------------------------结束-->
<!--删除事件---------------------------------------------开始-->
<script>
    $(function () {
        $(".btn_delete").on('click', function () {
            $(this).ajaxPost({
                confirm: '确认删除？',
                url: "{:url('system/admin_menu_delete')}",
                callback: function (json) {
                    $("#tr" + json.data).remove();
                }
            })
        })
    })
</script>
<!--删除事件---------------------------------------------结束-->